import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { FormBuilder, Validators } from '@angular/forms';
import { ApiService } from '../../../core/api/api.service';
import { MessageService } from '../../../core/service/message.service';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';

/**
 * 资产变化感知
 */

@Component({
    templateUrl: './assetsChange.html',
})
export class AssetsChangeComponent implements OnInit {
    pages = {
        pageNo: "1",       // 当前页
        pageSize: "10",      // 每页大小
        pages: "",      // 每页大小
        keyLevel: "",    // 监测级别 Key重点,NonKey非重点
        cityId: "3206",     // 市编号 (写死)
        areaId: "",  // 区编号
        status: "",  // 状态 Normal正常,Disabled已禁用,ToBeRectified待整改
        name: ""   // 企业名称};
    };
    departmentList = [];
    departmentTypes = {};
    memo;
    departmentTypesList = [];
    selectedRowData: any = {};
    isVisible = true;
    isLoading = false;
    editTable = false;
    list = []
    citys = [{
        title: '南通市',
        expanded: true,
        key: '3206',
        children: [
            {
                title: '南区',
                isLeaf: true,
                key: '320602'
            }        
        ]
    }]
    cityValue?:string;

    ngOnInit() {
        this.loadList();
    }
    changeCurrentPage(e) {
        this.pages.pageNo = e;
        this.loadList();
    }
    // 企業名稱搜索
    search(){
        this.loadList();
    }
    // 變更地址
    onChange($event): void {
        for (let i = 0; i < this.citys.length; i++) {
            const node = this.citys[i];
            if(node['key'] == $event){
                this.pages.cityId = $event;
            }else{
                this.pages.areaId = $event;
                for (let j = 0; j < node['children'].length; j++) {
                    const leaf = node['children'][j];
                    if(leaf['key'] == $event ){
                        this.pages.cityId = node['key'];
                        this.pages.areaId = $event;
                    };
                } 
            }
        }
        this.loadList();
    }
    loadList() {
        this.apiService.post('企业列表', this.pages).then((res: any) => {
            this.list = res.data['list'];
            this.pages.pageNo = res.data['pageNo'];
            this.pages.pages = res.data['pages'];
        })
    }
    constructor(
        private router: Router,
        private fb: FormBuilder,
        private apiService: ApiService,
        private message: MessageService,
        private nzMessageService: NzMessageService,
        private modal: NzModalService
    ) { }
}
